package com.ruipengkj.view.systemView;

import java.awt.Canvas;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.RoundRectangle2D;

import javax.swing.JDialog;

import com.ruipengkj.bean.TCommodity;
import com.ruipengkj.commons.util.barcode.CODE128BarCodeBean;
import com.ruipengkj.view.base.BaseDialog;

public class PrintLookCanvas extends Canvas {
	
	private static final long serialVersionUID = 1L;

	private TCommodity commodity = null;
	public PrintLookCanvas(TCommodity commodity) {
		this.commodity = commodity;
	} 
	
	@Override
	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		
		if (commodity == null || commodity.getCommodityID().equals(""))
			return;
		Image img=CODE128BarCodeBean.getCodeBeanImage(commodity.getBarcode());
		if (img != null){
			int x = 20;
			int y = 10;
			g2.draw(new RoundRectangle2D.Double(x-10, y-10, 2*142, 2*85, 10, 10));//画边框圆弧
			g2.setFont(new Font("新宋体", Font.PLAIN, 12)); // 设置字体
			g2.drawString("商品名称："+commodity.getName(), 2*x, 2*(9+5));//商品编号
			g2.setFont(new Font("新宋体", Font.PLAIN, 16)); // 设置字体
			g2.drawString("现价：￥"+commodity.getDiscountPrice(), 2*x, 2*(2*9+5));//是商品现价
			g2.setFont(new Font("新宋体", Font.PLAIN, 60)); // 设置字体
			g2.drawImage(img, 2*x, 2*(4*9+5), 2*113, 2*44, null);
		}
	}
	
	public void show() {
		new lookDialog(null, "打印预览", true, this);
	}
	
	class lookDialog extends BaseDialog{
		private static final long serialVersionUID = 1L;

		public lookDialog(JDialog jd, String title, boolean b, PrintLookCanvas look) {
			super(jd, title, b);
			this.setSize(320, 230);
			this.setLocationRelativeTo(null);
			this.setResizable(false);
			this.add(look);
			setVisible(true);
		} 
	}
}
